<%-- 
    Document   : erweimaAction
    Created on : 2014-10-14, 14:32:16
    Author     : Administrator
--%>

<%@page import="erwebma.AddCode"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="erwebma.client.j2se.MatrixToImageWriter"%>
<%@page import="com.google.zxing.common.BitMatrix"%>
<%@page import="com.google.zxing.MultiFormatWriter"%>
<%@page import="com.google.zxing.BarcodeFormat"%>
<%@page import="com.google.zxing.EncodeHintType"%>
<%@page import="java.util.Hashtable"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String data = request.getParameter("data");
    if (data != null) {
        int width = 128;
        int height = 128;
        String format = "png";
        //data  = AddCode.encode(data);
        data = "{\"tel\":{\"tel\":\"" + data + "\"}}";
        Hashtable hints = new Hashtable();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        BitMatrix bitMatrix = new MultiFormatWriter().encode(data, BarcodeFormat.QR_CODE, width, height, hints);
//    File outputFile = new File(path + new Date().getTime() + ".png");
        //MatrixToImageWriter.toBufferedImage(bitMatrix);
        BufferedImage bufi = MatrixToImageWriter.toBufferedImage(bitMatrix);
        response.reset();
        response.setContentType("image/png");
        ImageIO.write(bufi, "png", response.getOutputStream());
    }
%>